package utils;

public class TokenManager {
    private static final ThreadLocal<String> tokenStore = new ThreadLocal<>();

    // 线程安全存储
    public synchronized static void saveToken(String token) {
        tokenStore.set(token);
    }

    // 带过期校验的获取
    public static String getToken() {
        String token = tokenStore.get();
        if(token == null || token.isEmpty()) {
            throw new RuntimeException("未获取有效Token，请先执行登录接口");
        }
        return token;
    }
}